# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Hans-Nikolai Viessmann <hans AT viess DOT mn>

pkgname=plocate
pkgver=1.1.19
pkgrel=1
pkgdesc="Alternative to locate, faster and compatible with mlocate's database."
arch=('loong64' 'x86_64')
url="https://plocate.sesse.net"
license=('GPL2')
depends=('zstd' 'liburing' 'systemd')
makedepends=('meson')
conflicts=('mlocate')
provides=('mlocate' 'locate')
backup=('etc/updatedb.conf')
source=("${url}/download/${pkgname}-${pkgver}.tar.gz"
        'plocate.sysusers'
        'plocate.tmpfiles'
        'updatedb.conf')
sha256sums=('d95bc8ee8a9f79b9f69ce63df53fb85b202139f243bbb84c399555eda22e6165'
            '1713a8fc8b81f4a390bf8597c4c0e917474379002dcc984aad2f44218d10c82a'
            'adda399ac42f0faa002caab5bf932777c0006ae7c4387add859c9f77321b4202'
            'd00796741e2194032d0185b40de70ff5c8a11fda416a70434eb0aa2020981f91')

build() {
    cd $pkgname-$pkgver
    arch-meson \
        -Dinstall_cron=false \
        -Dinstall_systemd=true\
        -Dlocategroup=locate \
        ../build
    meson compile -C ../build
}

package() {
    cd $pkgname-$pkgver
    DESTDIR="$pkgdir" meson install -C ../build

    chgrp 21 "${pkgdir}/usr/bin/plocate"
    chmod 2755 "${pkgdir}/usr/bin/plocate"

    install -Dm644 ../plocate.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/plocate.conf"
    install -Dm644 ../plocate.sysusers "$pkgdir/usr/lib/sysusers.d/plocate.conf"
    install -Dm644 ../updatedb.conf "${pkgdir}/etc/updatedb.conf"
    ln -sf /usr/bin/plocate "$pkgdir/usr/bin/mlocate"
    ln -sf /usr/bin/plocate "$pkgdir/usr/bin/locate"
}
